package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.mapper.NursingProjectMapper;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class NursingProjectServiceImpl implements NursingProjectService {
    /**
     * 护理项目分页查询
     *
     * @param name
     * @param status
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Autowired
    private NursingProjectMapper nursingProjectMapper;
    @Override
    public PageResponse<NursingProjectVo> selectByPage(String name, Integer status, Integer pageNum, Integer pageSize) {
        //开启分页
        PageHelper.startPage(pageNum, pageSize);
        //正常查询数据
        Page<NursingProject> nursingProjects = nursingProjectMapper.selectByPage(name, status);
        //封装数据
        PageResponse<NursingProjectVo> response = PageResponse.of(nursingProjects, NursingProjectVo.class);
        return response;
    }

    /**
     * 新增护理项目
     * @param nursingProjectDto
     */
    @Override
    public int insert(NursingProjectDto nursingProjectDto) {
        NursingProject bean = BeanUtil.toBean(nursingProjectDto, NursingProject.class);
        return  nursingProjectMapper.insert(bean);
    }

    /**
     * 根据id查询护理信息
     * @param id
     * @return
     */
    @Override
    public NursingProjectVo getById(Long id) {
        NursingProject nursingProject =nursingProjectMapper.selectById(id);
        return BeanUtil.toBean(nursingProject, NursingProjectVo.class);
    }

    /**
     * 修改护理项目
     * @param nursingProjectDto
     */
    @Override
    public void update(NursingProjectDto nursingProjectDto) {
        NursingProject bean = BeanUtil.toBean(nursingProjectDto, NursingProject.class);
        nursingProjectMapper.update(bean);
    }

    /**
     * 状态修改
     * @param id
     * @param status
     */
    @Override
    public void updateStatus(Long id, Integer status) {
        NursingProject nursingProject = new NursingProject();
        nursingProject.setId(id);
        nursingProject.setStatus(status);
        nursingProjectMapper.update(nursingProject);
    }

    @Override
    public void delete(Long id) {
        nursingProjectMapper.deleteById(id);
    }

    @Override
    public List<NursingProject> list() {
       return nursingProjectMapper.list();

    }
}
